package org.fyp.synchrona.moodle.service;

import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;
import org.fyp.synchrona.moodle.service.util.OldData;

public class OldDataProcessor {
	
	OldData OldDataObj;
	
	static final Logger logger = Logger.getLogger(OldDataProcessor.class);
	
	public OldDataProcessor(OldData Od){
		OldDataObj = Od;
	}
	
	public void retriveOldParameters(String editPage){
		sesskey(editPage);// sesskey
		//maxfilesize(editPage);// MAX_FILE_SIZE
		//getid(editPage);// ID
		//getcourse(editPage);// course
		//getmform_showadvanced_last(editPage);
		//get_qf__user_editadvanced_form(editPage);
		//getusername(editPage);
		getfirstname(editPage);
		getlastname(editPage);
		getemail(editPage);
		//getmaildisplay(editPage);
		//getemailstop(editPage);
		//getmailformat(editPage);
		//getmaildigest(editPage);
		//getautosubscribe(editPage);
		//gettrackforums(editPage);
		//gethtmleditor(editPage);
		//getajax(editPage);
		//getscreenreader(editPage);
		getcity(editPage);
		//getcountry(editPage);
		//gettimezone(editPage);
		getdescription(editPage);
		//getlang(editPage);
		getinterests(editPage);
		//getimagealt(editPage);
		//getmform_showadvanced(editPage);
		geturl(editPage);
		//geticq(editPage);
		//getskype(editPage);
		//getaim(editPage);
		//getyahoo(editPage);
		//getmsn(editPage);
		//getidnumber(editPage);
		//getinstitution(editPage);
		//getdepartment(editPage);
		getphone1(editPage);
		getphone2(editPage);
		getaddress(editPage);
		//getsubmitbutton(editPage);
		
	}
	
	private void sesskey(String editPage) {
    	//System.out.println(editPage);
     	String[] array = editPage.split("=\"sesskey\"");
     	//String array1[] = new String[100];
     	//System.out.println("this is array 1 ::"+array[1]);
     	array = array[1].split("value=\"");
     	//System.out.println("printing array zero"+array[1]);
     	OldDataObj.setSessionKey(array[1].substring(0,(array[1].indexOf('\"'))));
     	logger.info("[MOODLE][old-data] session key ::"+OldDataObj.getSessionKey());
	}

	private void maxfilesize(String editPage) {
		String[] array = editPage.split("MAX_FILE_SIZE\" type=\"hidden\" value=\"");
		array = array[1].split("\" />");
		logger.info("[MOODLE][old-data] MAX_FILE_SIZE ::"+array[0]);
		OldDataObj.setMAX_FILE_SIZE(array[0]);
	}

	private void getid(String editPage) {
		String[] array = editPage.split("id\" type=\"hidden\" value=\"");
		array = array[1].split("\" />");
		logger.info("[MOODLE][old-data] ID ::"+array[0]);
		OldDataObj.setID(array[0]);
	}
	
	private void getcourse(String editPage){
		String[] array = editPage.split("<input name=\"course\" type=\"hidden\" value=\"");
		array = array[1].split("\" />");
		OldDataObj.setCourse(array[0]);
	}
	private void getmform_showadvanced_last(String editPage){
		String[] array = editPage.split("mform_showadvanced_last\" type=\"hidden\" value=\"");
		array = array[1].split("\" />");
		//System.out.println(array[0]);
		OldDataObj.setmform_showadvanced_last(array[0]);
	}
	private void get_qf__user_editadvanced_form(String editPage){
		String[] array = editPage.split("_qf__user_editadvanced_form\" type=\"hidden\" value=\"");
		array = array[1].split("\" />");
		//System.out.println(array[0]);
		OldDataObj.set_qf__user_editadvanced_form(array[0]);
	}
	private void getusername(String editPage){
		String[] array = editPage.split("size=\"20\" name=\"username\" type=\"text\" value=\"");
		array = array[1].split("\" onblur=\"");
		//System.out.println(array[0]);
		OldDataObj.setusername(array[0]);
	}
	private void getfirstname(String editPage){
		String[] array = editPage.split("firstname\" type=\"text\" value=\"");
		array = array[1].split("\" onblur=\"");
		//System.out.println(array[0]);
		OldDataObj.setfirstname(array[0]);
	}
	private void getlastname(String editPage){
		String[] array = editPage.split("lastname\" type=\"text\" value=\"");
		array = array[1].split("\" onblur=\"");
		//System.out.println(array[0]);
		OldDataObj.setlastname(array[0]);
	}
	private void getemail(String editPage) {
		String[] array = editPage.split("email\" type=\"text\" value=\"");
		array = array[1].split("\" onblur=\"");
		//System.out.println(array[0]);
		OldDataObj.setemail(array[0]);
	}
	private void getmaildisplay(String editPage) {
		//String[] array = editPage.split("text\" name=\"audioclipurl\" value=\"");
		//array = array[1].split("\" style=");
		OldDataObj.setmaildisplay("1");
	}
	private void getemailstop(String editPage) {
		//String[] array = editPage.split("input type=\"radio\" name=\"gender\" checked value=\"");
		//array = array[1].split("\" id=\"gender01\">");
		OldDataObj.setemailstop("1");
	}
	private void getmailformat(String editPage) {
		//String[] array = editPage.split("text\" name=\"birthmonth\" value=\"");
		//array = array[1].split("\" size=");
		OldDataObj.setmailformat("1");
		
	}
	private void getmaildigest(String editPage) {
		//
		//String[] array = editPage.split("text\" name=\"birthyear\" value=\"");
		//array = array[1].split("\" size=");
		OldDataObj.setmaildigest("1");
	}
	private void getautosubscribe(String editPage) {
		//text" name="birthday" value="
		//String[] array = editPage.split("text\" name=\"birthday\" value=\"");
		//array = array[1].split("\" size=");
		OldDataObj.setautosubscribe("1");
	}
	private void gettrackforums(String editPage) {
		//String[] array = editPage.split("checkbox\" name=\"showAstrologicalSigns\" checked value=\"");
		//array = array[1].split("\" id=\"showAstrologicalSigns");
		//System.out.println(array[0]);
		OldDataObj.settrackforums("0");
	}
	private void gethtmleditor(String editPage) {
		//String[] array = editPage.split("text\" name=\"url\" value=\"");
		//array = array[1].split("\" id=\"url");
		//System.out.println(array[0]);
		OldDataObj.sethtmleditor("0");
	}	
	private void getajax(String editPage) {
		//String[] array = editPage.split("text\" name=\"wishlisturl\" value=\"");
		//array = array[1].split("\" id=\"wishlisturl");
		//System.out.println(array[0]);
		OldDataObj.setajax("0");
	}
	private void getscreenreader(String editPage) {
		//String[] array = editPage.split("text\" name=\"imusername\" value=\"");
		//array = array[1].split("\" class");
		OldDataObj.setscreenreader("0");
	}
	private void getcity(String editPage) {
		String[] array = editPage.split("city\" type=\"text\" value=\"");
		array = array[1].split("\" onblur=\"validate");
		//System.out.println("hello"+array[0]);
		OldDataObj.setcity(array[0]);
	}
	private void getcountry(String editPage) {
		//String[] array = editPage.split("text\" name=\"widget.city\" value=\"");
		//array = array[1].split("\" id=\"widget.city\"");
		OldDataObj.setcountry("SL");
	}
	private void gettimezone(String editPage) {
		//String[] array = editPage.split("text\" name=\"widget.state\" value=\"");
		//array = array[1].split("\" id=\"widget.state\"");
		OldDataObj.settimezone("UTC-11.5");
		
	}
	private void getdescription(String editPage) {
		String[] array = editPage.split("form-textarea\" id=\"id_description\" name=\"description\" rows=\"10\" cols=\"45\">");
		array = array[1].split("</textarea>");
		logger.info("[Moodle]description ::"+array[0]);
		OldDataObj.setdescription(array[0]);
	}
	private void getlang(String editPage) {
		String[] array = editPage.split("en_utf8\" selected=\"selected\">");
		array = array[1].split("</option>");
		//System.out.println(array[0]);
		OldDataObj.setlang(array[0]);
		
	}
	
	private void getinterests(String editPage) {
		String[] array = editPage.split("interests\" id=\"id_interests\">");
		array = array[1].split("</textarea>");
		//System.out.println(array[0]);
		OldDataObj.setInterests(array[0]);
		
	}
	private void getimagealt(String editPage) {
		String[] array = editPage.split("imagealt\" type=\"text\" value=\"");
		array = array[1].split("\" id=\"id_imagealt");
		//System.out.println(array[0]);
		OldDataObj.setimagealt(array[0]);
		
	}
	private void getmform_showadvanced(String editPage) {
		String[] array = editPage.split("mform_showadvanced\" value=\"");
		array = array[1].split("\" type=\"submit\"");
		//System.out.println(array[0]);
		OldDataObj.setmform_showadvanced(array[0]);
	}
	private void geturl(String editPage) {
		String[] array = editPage.split("url\" type=\"text\" value=\"");
		array = array[1].split("\" id=\"id_url\"");
		//System.out.println(array[0]);
		OldDataObj.seturl(array[0]);
		
	}
	private void geticq(String editPage) {
		String[] array = editPage.split("icq\" type=\"text\" value=\"");
		array = array[1].split("\" id=\"id_icq\"");
		//System.out.println(array[0]);
		OldDataObj.seticq(array[0]);
		
	}
	private void getskype(String editPage) {
		String[] array = editPage.split("skype\" type=\"text\" value=\"");
		array = array[1].split("\" id=\"id_skype\"");
		//System.out.println(array[0]);
		OldDataObj.setskype(array[0]);
		
	}
	private void getaim(String editPage) {
		String[] array = editPage.split("aim\" type=\"text\" value=\"");
		array = array[1].split("\" id=\"id_aim\"");
		//System.out.println(array[0]);
		OldDataObj.setaim(array[0]);
		
	}
	//
	private void getyahoo(String editPage){
		String[] array = editPage.split("yahoo\" type=\"text\" value=\"");
		array = array[1].split("\" id=\"id_yahoo\"");
		//System.out.println(array[0]);
		OldDataObj.setyahoo(array[0]);
	}
	
	private void getmsn(String editPage){
		String[] array = editPage.split("msn\" type=\"text\" value=\"");
		array = array[1].split("\" id=\"id_msn\"");
		//System.out.println(array[0]);
		OldDataObj.setmsn(array[0]);
	}
	
	private void getidnumber(String editPage){
		String[] array = editPage.split("idnumber\" type=\"text\" value=\"");
		array = array[1].split("\" id=\"id_idnumber\"");
		//System.out.println(array[0]);
		OldDataObj.setidnumber(array[0]);
	}
	
	private void getinstitution(String editPage){
		String[] array = editPage.split("institution\" type=\"text\" value=\"");
		array = array[1].split("\" id=\"id_institution\"");
		//System.out.println(array[0]);
		OldDataObj.setinstitution(array[0]);
	}
	//
	private void getdepartment(String editPage){
		String[] array = editPage.split("department\" type=\"text\" value=\"");
		array = array[1].split("\" id=\"id_department\"");
		//System.out.println(array[0]);
		OldDataObj.setdepartment(array[0]);
	}
	private void getphone1(String editPage){
		String[] array = editPage.split("phone1\" type=\"text\" value=\"");
		array = array[1].split("\" id=\"id_phone1\"");
		//System.out.println(array[0]);
		OldDataObj.setphone1(array[0]);
	}
	
	private void getphone2(String editPage){
		String[] array = editPage.split("phone2\" type=\"text\" value=\"");
		array = array[1].split("\" id=\"id_phone2");
		//System.out.println(array[0]);
		OldDataObj.setphone2(array[0]);
	}
	private void getaddress(String editPage){
		String[] array = editPage.split("address\" type=\"text\" value=\"");
		array = array[1].split("\" id=\"id_address\"");
		//System.out.println(array[0]);
		OldDataObj.setaddress(array[0]);
	}
	private void getsubmitbutton(String editPage){
		String[] array = editPage.split("submitbutton\" value=\"");
		array = array[1].split("\" type=\"submit\"");
		//System.out.println(array[0]);
		OldDataObj.setsubmitbutton(array[0]);
	}
	
	
	
	
}
